#ifndef _KLAS_PRIMITIVE_NODE_HPP_
#define _KLAS_PRIMITIVE_NODE_HPP_

#include "../include/Node.hpp"
#include "../include/Point.hpp"
#include "../include/Libs.hpp"

#include <list>
using namespace std;

namespace klas
{
	//! The primitive node renders polygons.
	class PrimitiveNode : public Node
	{
		public:
			
			//! Ctor.
			PrimitiveNode();
			
			//! Ctor.  Creates a rectangle.
			/*! \param pos The position / center of the node.
					\param rect The rectangle to create.  These coordinates assume that the pos is the origin.
					\param col The color of the rectangle. */
			PrimitiveNode(const Vector2<Real>& pos, const Rectangle<Real>& rect, const Color& col);
			
			//! Ctor.  Creates a circle.
			/*! \param center The center of the circle.
				  \param radius The radius of the circle.
					\param col The color of the circle.
					\param accuracy How accurate should the circle be?  1 is as accurate as
										possible, while something like 12 will make a jagged circle. */
			PrimitiveNode(const Vector2<Real>& center, Real radius, const Color& col,
				iReal accuracy=6);
			
			//! Ctor.  Creates a line.
			/*! \param pos The position / center of the node.
					\param ptA A point to construct the node with, assumes pos is the origin. 
					\param ptB A point to construct the node with, assumes pos is the origin. */
			PrimitiveNode(const Vector2<Real>& pos, const Point& ptA, const Point& ptB);
			
			//! Ctor.  Creates a triangle.
			/*! \param pos The position / center of the node.
					\param ptA A point to construct the node with, assumes pos is the origin.
					\param ptB A point to construct the node with, assumes pos is the origin. 
					\param ptB A point to construct the node with, assumes pos is the origin. */
			PrimitiveNode(const Vector2<Real>& pos, const Point& ptA, const Point& ptB, const Point& ptC);
			
			//! Dtor.
			~PrimitiveNode();
			
			//! Gets a deep copy of the node.
			/*! \return A deep copy of the node.  You have to call delete on the new node. */
			virtual PrimitiveNode* getDeepCopy();
			
      //! Gets what type of this node is.  IE: Texture, Primitive, etc.
      /*! \return The type of the node. */
      virtual iReal getNodeType() const;

			//! Adds the point to the primitive.
      /*! \param pt The point to add.
      		\param flags Additional parameters to consider when adding the node. Use PrimitiveNode:: 
      		\return The index of the point. */
			iReal addPoint(const Point& pt, uint8 flags=0x00);
			
			//! Changes the color of a point.
			/*! \param col The new color.
					\param idx The index of the point to change.  If the idx is negative, all
											points are changed to that color. */
			void changeColor(const Color& col, iReal idx=-1);
			
			//! Renders the Primitive
			/*! \param camera The camera (used to offset the node. */
			void render(const Rectangle<Real>& camera);
			
			enum flags {
				ADD_FRONT //! Adds the node to the front of the list of nodes.
			};
			
		private:
			
			//! The points that compose this primitive.
			list<Point> m_pts;
			
			//! The center of the node.
			Vector2<Real> m_center;
		
			//! Recalcualtes the center of the node.
			void recalculateCenter();
							
	};
}

#endif
